import { createStore } from 'vuex'

export default createStore({
    state: {
        // 是否显示登录页面
        showLogView: false,
        // 仓库  用户信息
        userInfo: '',
        // 退出登录 页面的显示与隐藏
        changeBig: null,
        //
        videoInfo: {
            isMuted: true,
            currentVol: 0,
            defaultVol: 30,
            currentRate: 1,
            currentQuality: -1
        },
        // 控制回复评论框显示与隐藏
        commentOneShow:null,
        commentTwoShow:null,
        // 图标菜单 显示与隐藏
        menuIndex:null,
        menuIndex2:null,
        // 弹出框 显示与隐藏
        isShowDelete:null,
        isShowDeleteTwo:null,
        // 全局表情
        emojiList:[],
        // 总评论数
        commentsChange:0,
        //已点赞数组
        commentLikeUsers:[],
        //false: 评论默认排序规则，true：按时间降序
        latest:false,
        // 合集列表的切换
        compilationChange:false,
    },
    getters: {

    },
    mutations: {
        changeCompilation(state){
            state.compilationChange = !state.compilationChange
        },
        changeLatest(state,latest){
          state.latest = latest
        },
        // 重置用户在当前视频的点赞
        changeCommentLikeStatus(state) {
            state.commentLikeUsers = [];
        },
        // 保存用户在当前视频的点赞
        saveCommentLikeUsers(state,commentLikeUsers){
            state.commentLikeUsers = commentLikeUsers
        },
        saveCommentTotal(state,commentsChange){
            state.commentsChange = commentsChange
        },
        //改变评论框的显示与隐藏
        changeOneComment(state,id) {
            if(!state.userInfo) return
            // 控制 只允许出现一个评论框
            if(state.commentTwoShow != null){
                state.commentTwoShow = null
            }
            state.commentOneShow = id
        },
        changeTwoComment(state,id) {
            if(!state.userInfo) return
            if(state.commentOneShow != null){
                state.commentOneShow = null
            }
            state.commentTwoShow = id
        },
        // 隐藏一级、子级评论
        outOneAndTwoComment(state){
            state.commentOneShow = null
            state.commentTwoShow = null
        },
        // 删除弹出框 显示与隐藏
        changeShowDelete(state,id){
            if (state.isShowDeleteTwo != null){
                state.isShowDeleteTwo = -1
            }
            state.isShowDelete = id
        },
        changeShowDeleteTwo(state,id){
            if (state.isShowDelete != null){
                state.isShowDelete = -1
            }
            state.isShowDeleteTwo = id
        },
        // 关闭删除框
        closeShowDelete(state){
            state.isShowDelete = null
            state.isShowDeleteTwo = null
        },
        // 删除、举报图标菜单的显示与隐藏
        changeMenuIndex(state,index){
            if(state.menuIndex2 != null){
                state.menuIndex2 = null
            }
            state.menuIndex = index
        },
        changeMenuIndex2(state,index){
            if(state.menuIndex != null){
                state.menuIndex = null
            }
            state.menuIndex2 = index
        },
        // 鼠标移出竖三角 隐藏删除按钮
        outMenuShow(state){
            state.menuIndex = null
            state.menuIndex2 = null
        },
        // 存储表情
        saveEmojiList(state,list){
            state.emojiList = list
        },
        //改变登录页的显示与隐藏
        changeLogView(state) {
                        state.showLogView = !state.showLogView
        },
        //设置用户信息（logReg.vue--206）this.$store.commit('setUser', res.data)
        setUser(state, userInfo) {
            state.userInfo = userInfo
            //console.log("已将userInfo存入store")
        },
        changeMuted(state) {
            state.videoInfo.isMuted = !state.videoInfo.isMuted
        },
        setCurrentVol(state, currentVol) {
            state.videoInfo.currentVol = currentVol
        },
        setRate(state, currentRate) {
            state.videoInfo.currentRate = currentRate
        },
        setQuality(state, currentQuality) {
            state.videoInfo.currentQuality = currentQuality
        },
        //退出登录，并删除本地存储空间中的userInfo信息
        logout(state) {
            console.log('logout');
            state.userInfo = ''
            // 删除localStorage存储的信息
            localStorage.removeItem('userInfo')
            // changeBig: null
            state.changeBig = null
        }
    },
    actions: {},
    modules: {}
})
